#include <memory>
#include "TcpServer.hpp"
#include "Calculator.hpp"

Calculator calculator;

void DefaultOnMessage(weak_ptr<Connection> conn)
{
    if(conn.expired()) 
        return;
    auto connection_ptr = conn.lock();
    cout << "上层获得数据： " << connection_ptr->InBuffer() << endl;
    string response_str = calculator.Handler(connection_ptr->InBuffer()); 
    if(response_str.empty()) 
        return;
    log(Debug, "%s", response_str.c_str());

    connection_ptr->AppendOutBuffer(response_str);
    auto tcpserver = connection_ptr->_tcp_server_ptr.lock();
    tcpserver->Sender(connection_ptr);
}

int main()
{
    shared_ptr<TcpServer> svr(new TcpServer(8080, DefaultOnMessage));

    svr->Init();
    svr->Start();

    return 0;
}